package punctuatedEquilibriumTest;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

import punctuatedEquilibrium.FloatComparison;
import punctuatedEquilibrium.Trait;

public class TraitTest {

	private static final double	SUM_ONE			= 8;
	private static final double	TRAIT_VALUE_ONE	= 5;
	private static final double	VALUE_TO_ADD	= 3;

	Trait						trait;

	@Before
	public void setUp() {
		trait = new Trait(TRAIT_VALUE_ONE);
	}

	@Test
	public void testAddValue() {
		trait.add(VALUE_TO_ADD);
		double reportedValue = trait.reportValue();
		assertEquals(SUM_ONE, reportedValue,
				tolerableErrorBasedOnExpectedValue(SUM_ONE));
	}

	@Test
	public void testCreate() {
		assertNotNull(trait);
	}

	@Test
	public void testReportValue() {
		double reportedValue = trait.reportValue();
		assertEquals(TRAIT_VALUE_ONE, reportedValue,
				tolerableErrorBasedOnExpectedValue(TRAIT_VALUE_ONE));
	}

	private double tolerableErrorBasedOnExpectedValue(double expectedValue) {
		return FloatComparison
				.tolerableErrorDependingOnExpectedValue(expectedValue);
	}

}
